package online.dgyj.nlecloudii;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.util.Log;
import android.view.WindowManager;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

import java.util.List;

import cn.com.newland.nle_sdk.requestEntity.SignIn;
import cn.com.newland.nle_sdk.responseEntity.SensorInfo;
import cn.com.newland.nle_sdk.responseEntity.User;
import cn.com.newland.nle_sdk.responseEntity.base.BaseResponseEntity;
import cn.com.newland.nle_sdk.util.NCallBack;
import cn.com.newland.nle_sdk.util.NetWorkBusiness;

@SuppressLint("SetTextI18n")
public class MainActivity extends AppCompatActivity {
    private static final String baseURL = "https://api.nlecloud.com/";
    private NetWorkBusiness netWorkBusiness;
    private static final String user = "";
    private static final String pwd = "";
    private static final String projectID = "";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EdgeToEdge.enable(this);
        setContentView(R.layout.activity_main);
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
            Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
            return insets;
        });
        getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);

        netWorkBusiness = new NetWorkBusiness("",baseURL);
        netWorkBusiness.signIn(new SignIn(user, pwd), new NCallBack<BaseResponseEntity<User>>(getApplicationContext()) {
            @Override
            protected void onResponse(BaseResponseEntity<User> userBaseResponseEntity) {
                String accessToken = userBaseResponseEntity.getResultObj().getAccessToken();
                Log.d("AccessToken",accessToken);
                netWorkBusiness = new NetWorkBusiness(accessToken,baseURL);
            }
        });
    }

    /**
     * 获取传感器数据
     */
    private void GetData(){
        netWorkBusiness.getSensors("966169", "temp", new NCallBack<BaseResponseEntity<List<SensorInfo>>>(getApplicationContext()) {
            @Override
            protected void onResponse(BaseResponseEntity<List<SensorInfo>> listBaseResponseEntity) {
                Log.d("Sensor Data",listBaseResponseEntity.getResultObj().get(0).getValue());
            }
        });
    }

    /**
     * 发送控制指令
     */
    private void SendData(){
        netWorkBusiness.control("966169", "button", 1, new NCallBack<BaseResponseEntity>(getApplicationContext()) {
            @Override
            protected void onResponse(BaseResponseEntity baseResponseEntity) {

            }
        });
    }
}